package com.l024.framework.base;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.l024.framework.event.EventBusManager;
import com.l024.framework.event.MessageEvent;
import com.l024.framework.utils.Logutils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * @author wu_ming_zhi_bei
 * @date 2020/2/27 10:29
 * @Notes
 */
public class BaseActivity extends AppCompatActivity {

    //注册EventBus
    /**
     * Event步骤
     * 1.注册
     * 2.声明注册 onEvent
     * 3.发送事件
     */
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBusManager.register(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBusManager.unregister(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent message) {
        Logutils.i("接收到消息");
        if(message.getType()==EventBusManager.FLAY_UPDATE_FRIEND_LIST){
            Toast.makeText(this, "EventBus:更新好友列表", Toast.LENGTH_SHORT).show();
        }
    }
}
